﻿var showMode = false; var timer;
//implemented by sanal on Feb 25, 2008
var myWidth = 0;
var myHeight = 0;
var scrOfX = 0;
var scrOfY = 0;
var browserNetScape = false;
function setVariables() {
    if (navigator.appName == "Netscape")
        browserNetScape = true;
}
function loadthis() {
    setVariables();
}
function setWindowSize() {
    //var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    //window.alert( 'Width = ' + myWidth );
    //window.alert( 'Height = ' + myHeight );
}
function getScrollXY() {
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //return [ scrOfX, scrOfY ];
}

function select() {
    var theForm = document.getElementById("aspnetForm"), z = 0;
    for (z = 0; z < theForm.length; z++) {
        if (theForm[z].type == 'checkbox') {
            if (theForm[z].checked == true) {
                //bRet = true;alert
                return true;
            }
        }
    }

    return false;
}

function SelectDeselectAll() {
    var theForm = document.getElementById("aspnetForm"), z = 0;
    var isChecked = null;
    for (z = 0; z < theForm.length; z++) {
        if (theForm[z].type == 'checkbox') {
            //alert(isChecked);
            if (isChecked == null) isChecked = theForm[z].checked;
            //alert(theForm[z].id);
            theForm[z].checked = isChecked;
            //	            if (theForm[z].checked == true) 
            //	            {
            //	            //bRet = true;alert
            //	            return true;
            //	            }
        }
    }
}

function close1() {
    showMode = false;
    document.getElementById("bkPanel").style.display = "none";
    document.getElementById("div_comments").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder3_lblComments").innerHTML = "";
    //document.getElementById("ctl00_ContentPlaceHolder3_lblComments").firstChild.nodeValue = "";
    clearTimeout(timer);
}

function close2() {
    showMode = false;
    document.getElementById("div_comm").style.display = "none";
    document.getElementById("div_comm1").style.display = "none";
    clearTimeout(timer);
}

function open2() {
    setVariables();
    showMode = true;
    setWindowSize();
    getScrollXY();
    document.getElementById("div_comm").style.display = "block";
    document.getElementById("div_comm1").style.display = "block";
    if (browserNetScape == true) {
        document.getElementById("div_comm").style.width = '';
        document.getElementById("div_comm").style.left = '';
        document.getElementById("div_comm").style.top = '';
        document.getElementById("div_comm").style.height = '';
        document.getElementById("div_comm").style.left = "0px";
        document.getElementById("div_comm").style.top = "0px";
        document.getElementById("div_comm").style.width = (myWidth + scrOfX - 8) + "px";
        document.getElementById("div_comm").style.height = (myHeight + scrOfY - 8) + "px";
        var lef = ((myWidth - document.getElementById("div_comm1").offsetWidth) / 2);
        var top = (myHeight - document.getElementById("div_comm1").offsetHeight) / 2 + scrOfY;
        document.getElementById("div_comm1").style.left = lef + "px";
        document.getElementById("div_comm1").style.top = top + "px";
    }
    else {
        document.getElementById("div_comm").style.left = "0";
        document.getElementById("div_comm").style.top = "0";
        document.getElementById("div_comm").style.width = myWidth + scrOfX;
        document.getElementById("div_comm").style.height = myHeight + scrOfY;
        document.getElementById("div_comm1").style.left = (myWidth - document.getElementById("div_comm1").offsetWidth) / 2;
        document.getElementById("div_comm1").style.top = (myHeight - document.getElementById("div_comm1").offsetHeight) / 2;
    }
    if (showMode == true) timer = setTimeout("open2()", 300);
}

function open1() {
    setVariables();
    showMode = true;
    setWindowSize();
    getScrollXY();
    document.getElementById("bkPanel").style.display = "block";
    document.getElementById("div_comments").style.display = "block";
    if (browserNetScape == true) {
        document.getElementById("bkPanel").style.width = '';
        document.getElementById("bkPanel").style.left = '';
        document.getElementById("bkPanel").style.top = '';
        document.getElementById("bkPanel").style.height = '';
        document.getElementById("bkPanel").style.left = "0px";
        document.getElementById("bkPanel").style.top = "0px";
        document.getElementById("bkPanel").style.width = (myWidth + scrOfX - 8) + "px";
        document.getElementById("bkPanel").style.height = (myHeight + scrOfY - 8) + "px";
        var lef = ((myWidth - document.getElementById("div_comments").offsetWidth) / 2);
        var top = (myHeight - document.getElementById("div_comments").offsetHeight) / 2 + scrOfY;
        document.getElementById("div_comments").style.left = lef + "px";
        document.getElementById("div_comments").style.top = top + "px";
    }
    else {
        document.getElementById("bkPanel").style.left = "0";
        document.getElementById("bkPanel").style.top = "0";
        document.getElementById("bkPanel").style.width = myWidth + scrOfX;
        document.getElementById("bkPanel").style.height = myHeight + scrOfY;
        document.getElementById("div_comments").style.left = (myWidth - document.getElementById("div_comments").offsetWidth) / 2;
        document.getElementById("div_comments").style.top = (myHeight - document.getElementById("div_comments").offsetHeight) / 2;
    }
    if (showMode == true) timer = setTimeout("open1()", 300);
}

function closeHistory(div_id) {
    showMode = false;
    document.getElementById("bkPanel").style.display = "none";
    document.getElementById(div_id).style.display = "none";
    clearTimeout(timer);
}

function openHistory(div_id) {
    setVariables();
    showMode = true;
    setWindowSize();
    getScrollXY();
    document.getElementById("bkPanel").style.display = "block";
    document.getElementById(div_id).style.display = "block";
    if (browserNetScape == true) {
        document.getElementById("bkPanel").style.width = '';
        document.getElementById("bkPanel").style.left = '';
        document.getElementById("bkPanel").style.top = '';
        document.getElementById("bkPanel").style.height = '';
        document.getElementById("bkPanel").style.left = "0px";
        document.getElementById("bkPanel").style.top = "0px";
        document.getElementById("bkPanel").style.width = (myWidth + scrOfX - 8) + "px";
        document.getElementById("bkPanel").style.height = (myHeight + scrOfY - 8) + "px";
        var lef = ((myWidth - document.getElementById(div_id).offsetWidth) / 2);
        var top = (myHeight - document.getElementById(div_id).offsetHeight) / 2 + scrOfY;
        document.getElementById(div_id).style.left = lef + "px";
        document.getElementById(div_id).style.top = top + "px";
    }
    else {
        document.getElementById("bkPanel").style.left = "0";
        document.getElementById("bkPanel").style.top = "0";
        document.getElementById("bkPanel").style.width = myWidth + scrOfX;
        document.getElementById("bkPanel").style.height = myHeight + scrOfY;
        document.getElementById(div_id).style.left = (myWidth - document.getElementById(div_id).offsetWidth) / 2;
        document.getElementById(div_id).style.top = (myHeight - document.getElementById(div_id).offsetHeight) / 2;
    }
    var stemp = "openHistory('" + div_id + "')";
    if (showMode == true) timer = setTimeout(stemp, 300);
}

function getComments(af_row_id, status) {
    try {
        if (status == "Approved") {
            document.getElementById("ctl00_ContentPlaceHolder3_lblComments").innerHTML = "Approve with comments";
            //document.getElementById("ctl00_ContentPlaceHolder3_lblComments").firstChild.nodeValue = "Approve with comments";
        }
        else if (status == "Rejected") {
            document.getElementById("ctl00_ContentPlaceHolder3_lblComments").innerHTML = "Reject with comments";
            //document.getElementById("ctl00_ContentPlaceHolder3_lblComments").firstChild.nodeValue = "Reject with comments";
        }
        document.getElementById("ctl00_ContentPlaceHolder3_hf_af_row_id").value = af_row_id;
        document.getElementById("ctl00_ContentPlaceHolder3_hf_Status").value = status;
    }
    catch (Ex) {
        //alert(Ex.message);
    }
    open1();

    return false;
}

function getComm() {
    if (select() == true) {
        //alert(document.getElementById("ctl00_ContentPlaceHolder3_hf_selected").value);

        try {
            document.getElementById("ctl00_ContentPlaceHolder3_hf_Status").value = "Approved";
        }
        catch (Ex) {
            //alert(Ex.message);
        }
        open2();
    }
    else
        alert("Select any work item to continue"); //document.getElementById("ctl00_ContentPlaceHolder3_lbl_message").value = "Please select atleast one work item";

    return false;
}

function Cancel2() {
    document.getElementById("ctl00_ContentPlaceHolder3_txtComm").value = "";
    document.getElementById("ctl00_ContentPlaceHolder3_hf_Status").value = "";
    close2();
    return false;
}

function Cancel() {
    document.getElementById("ctl00_ContentPlaceHolder3_txtComments").value = "";
    document.getElementById("ctl00_ContentPlaceHolder3_hf_af_row_id").value = "";
    document.getElementById("ctl00_ContentPlaceHolder3_hf_Status").value = "";
    close1();
    return false;
}

function validate() {
    document.getElementById("message").innerHTML = "";
    if (document.getElementById("ctl00_ContentPlaceHolder3_txtComments").value == "") {
        document.getElementById("message").innerHTML = "Please specify a comment."
        //document.getElementById("message").firstChild.nodeValue = "Please specify a comment.";
        return false;
    }
    else {
        document.getElementById("ctl00_ContentPlaceHolder3_hfComments").value = document.getElementById("ctl00_ContentPlaceHolder3_txtComments").value;
        document.getElementById("ctl00_ContentPlaceHolder3_txtComments").value = "";
        document.getElementById("message").innerHTML = "";
        close1();
        return true;
    }
}

function validate2() {
    document.getElementById("message2").innerHTML = "";
    if (document.getElementById("ctl00_ContentPlaceHolder3_txtComm").value == "") {
        document.getElementById("message2").innerHTML = "Please specify a comment."
        //document.getElementById("message2").firstChild.nodeValue = "Please specify a comment.";
        return false;
    }
    else {
        document.getElementById("ctl00_ContentPlaceHolder3_hfcomments").value = document.getElementById("ctl00_ContentPlaceHolder3_txtComm").value;
        document.getElementById("ctl00_ContentPlaceHolder3_txtComm").value = "";
        document.getElementById("message2").innerHTML = "";
        close2();
        return true;
    }
}

function showHistory(div_id) {
    openHistory(div_id);
}

Sys.Application.add_init(Init);
var prm = null;
function Init(sender) {
    prm = Sys.WebForms.PageRequestManager.getInstance();
    //Ensure EnablePartialRendering isn't false which will prevent      
    //accessing an instance of the PageRequestManager      
    if (prm) {
        if (!prm.get_isInAsyncPostBack()) {
            prm.add_initializeRequest(InitRequest);
        }
    }
}

function InitRequest(sender, args) {
    if (prm.get_isInAsyncPostBack())// & args.get_postBackElement().id ==          'btnRefresh') 
    {
        //Could abort current request by using:  prm.abortPostBack();            
        //Cancel most recent request so that previous request will complete          
        //and display         
        args.set_cancel(true);
        //alert("A request is currently being processed.  Please wait before refreshing again.");      
    }
}

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);

function EndRequest(sender, eventArgs) {
    if (eventArgs.get_error() != undefined && eventArgs.get_error().httpStatusCode == '500') {
        var errorMessage = eventArgs.get_error().message;
        eventArgs.set_errorHandled(true);
        //alert(errorMessage);    
    }
}
function navigatePages(argument) {
    try {
        var pageVal = document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value;
        //alert(pageVal);
        if (argument == "-1") {
            if (pageVal != "0")
                document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = eval(pageVal) - 1;
        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = eval(pageVal) + 1;
        }
    }

    catch (Ex) {
        //alert(Ex.message);
    }
    //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value);
}

function navigatePagesSetValue(argument) {
    try {
        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = argument;
    }

    catch (Ex) {
        //alert(Ex.message);
    }
}

function sortdata(columnname, sortorder, sortdata) {
    try {
        //alert(columnname);
        //alert(sortorder);
        //alert(sortdata);


        if (columnname == sortdata) {
            //alert("inside if");
            document.getElementById("ctl00_ContentPlaceHolder3_hfSort").value = columnname;
            if (document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value == "asc") {
                //alert("inside if");
                document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value = "desc";
            }
            else if (document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value == "desc") {
                //alert("inside else if");
                document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value = "asc";
            }
            else {
                //alert("inside else else");
                document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value = "asc";
            }
        }
        else {
            //alert("inside esle");
            document.getElementById("ctl00_ContentPlaceHolder3_hfSort").value = columnname;
            document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value = "asc";
        }






        //            document.getElementById("ctl00_ContentPlaceHolder3_hfSort").value = columnname;
        //            
        //            if(document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder")!= null)
        //            {
        //                var strsortorder = document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value;
        //                if(strsortorder =="")
        //                {
        //                    document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value="asc";
        //                    
        //                    //alert("inside if");
        //                }
        //                else
        //                {
        //                    if(document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value=="desc")
        //                    {
        //                   // alert("inside else if");
        //                        document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value="asc";
        //                    }
        //                    else if(document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value=="asc")
        //                    {
        //                   // alert("inside else else if");
        //                      document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value="desc";
        //                    }
        //                    else
        //                    {
        //                    //alert("inside else else");
        //                        document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value="asc";
        //                    }
        //                }
        //                
        //                var strsortorder = document.getElementById("ctl00_ContentPlaceHolder3_hfSortOrder").value;
        //                //alert(strsortorder);
        //            }
    }
    catch (Ex) {
    }
}
function resettoZero() {
    //alert("k");
    if (document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId") != null) {
        //alert("inseid");
        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = "0";
        //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value);
        //  alert("after");
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfddobject") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfddobject").value = document.getElementById("ctl00_ContentPlaceHolder3_ddobject").value;
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfddcreatedby") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfddcreatedby").value = document.getElementById("ctl00_ContentPlaceHolder3_ddcreatedby").value;
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfddcreatedat") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfddcreatedat").value = document.getElementById("ctl00_ContentPlaceHolder3_ddcreatedat").value;
    }

}